/**
 * Created by zengyx on 16/12/15.
 */
import { isUseQiniu } from '@/utils/constance'
import { getFileDomin } from '../actions'
import send from './http'

const CACHE_ACTION = 'common.getDicCache'
const MENU_ACTION = 'common.getUserInMenu'
const SYSTEM_CONFIG_ACTION = 'system.getUpNf'
const SYSTEM_GET_CAPTCHA = 'system.getCaptcha'
const SOCKET_PUSH_ACTION = 'system.getSocketPushServiceAddress'
const SOCKET_PUSH_LOGOUT = 'system.pushSocketLogout'
// const WEIXINUPTOKEN = 'app.weixin.getUptoken'
// const WEIXINUPTOKEN = isUseQiniu() ? 'app.weixin.getUptoken' : 'app.oss.getPresignedUrl'
const GETCCCONFIGURL = 'config.system.getCCConfigUrl'
export default {

  getDicCache (postData) {
    let req = {
      data: postData,
      action: CACHE_ACTION,
      errMsg: 'getCacheError'
    }
    return send.fetch(req, 'post', true)
  },

  getUserInMenu (postData) {
    let req = {
      data: postData,
      action: MENU_ACTION
    }
    return send.fetch(req, 'post')
  },

  initSystemConfig (postData) {
    let req = {
      data: postData,
      action: SYSTEM_CONFIG_ACTION
    }
    return send.fetchByPublic(req, 'get', true)
  },
  getCaptchaAction (postData) {
    let req = {
      data: postData,
      action: SYSTEM_GET_CAPTCHA
    }
    return send.fetchByPublic(req, 'get', true)
  },
  getSocketPushAddress (postData) {
    let req = {
      data: postData,
      action: SOCKET_PUSH_ACTION
    }
    return send.fetchByPublic(req, 'get', true)
  },

  pushSocketLogout (postData) {
    let req = {
      data: postData,
      action: SOCKET_PUSH_LOGOUT
    }
    return send.fetchByPublicSycn(req)
  },

  clearSession (postData) {
    let req = {
      data: postData,
      action: 'app.user.clearSession'
    }
    return send.fetchByActionSycn(req)
  },

  getWeinxinQiniuUptoken (data) {
    let req = {
      data,
      action: isUseQiniu() ? 'app.weixin.getUptoken' : 'app.oss.getPresignedUrl'
    }
    return send.fetch(req, 'post')
  },

  getCCConfigUrl (data) {
    let req = {
      data: data,
      action: GETCCCONFIGURL
    }
    return send.fetch(req, 'post')
    // return send.fetchByPublic(req, 'get', true)
  },
  collectLog (data) {
    let req = {
      data: data,
      action: 'app.collect.clientLog'
    }
    return send.fetch(req, 'post', true)
  },
  /**
   * 导出Xls
   */
  exportXls (data) {
    let req = {
      data,
      action: 'app.excel.exportXls'
    }
    return send.fetch(req, 'post')
  },
  // 获取七牛文件域名
  getFileDomin (data) {
    let req = {
      data,
      action: 'common.getFileDomain'
    }
    return send.fetch(req, 'post')
  }
}
